<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="图片路径" prop="pictureUrl">
        <el-input
          v-model="queryParams.pictureUrl"
          placeholder="请输入图片路径"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="材料路径" prop="sourcesUrl">
        <el-input
          v-model="queryParams.sourcesUrl"
          placeholder="请输入材料路径"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发布时间" prop="releaseTime">
        <el-date-picker clearable
          v-model="queryParams.releaseTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择发布时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="参与人员" prop="participants">
        <el-input
          v-model="queryParams.participants"
          placeholder="请输入参与人员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="浏览次数" prop="viewsTimes">
        <el-input
          v-model="queryParams.viewsTimes"
          placeholder="请输入浏览次数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="栏目" prop="contentColumn">
        <el-input
          v-model="queryParams.contentColumn"
          placeholder="请输入栏目"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否有心得体会" prop="haveExperience">
        <el-input
          v-model="queryParams.haveExperience"
          placeholder="请输入是否有心得体会"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="文件号" prop="fileNum">
        <el-input
          v-model="queryParams.fileNum"
          placeholder="请输入文件号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户ID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门ID" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入部门ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公告ID" prop="noticeId">
        <el-input
          v-model="queryParams.noticeId"
          placeholder="请输入公告ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="课题名称" prop="issueName">
        <el-input
          v-model="queryParams.issueName"
          placeholder="请输入课题名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="课题类别" prop="topicCategory">
        <el-input
          v-model="queryParams.topicCategory"
          placeholder="请输入课题类别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="课题年度" prop="projectYear">
        <el-input
          v-model="queryParams.projectYear"
          placeholder="请输入课题年度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="承研单位" prop="researchUnit">
        <el-input
          v-model="queryParams.researchUnit"
          placeholder="请输入承研单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="课题负责人" prop="projectLeader">
        <el-input
          v-model="queryParams.projectLeader"
          placeholder="请输入课题负责人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="课题成员" prop="subjectMembers">
        <el-input
          v-model="queryParams.subjectMembers"
          placeholder="请输入课题成员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经费类算" prop="fundingCategories">
        <el-input
          v-model="queryParams.fundingCategories"
          placeholder="请输入经费类算"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="附件" prop="annex">
        <el-input
          v-model="queryParams.annex"
          placeholder="请输入附件"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="进展情况" prop="progress">
        <el-input
          v-model="queryParams.progress"
          placeholder="请输入进展情况"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="进度周期预警" prop="progressPeriod">
        <el-input
          v-model="queryParams.progressPeriod"
          placeholder="请输入进度周期预警"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建者" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入创建者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker clearable
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新者" prop="updateBy">
        <el-input
          v-model="queryParams.updateBy"
          placeholder="请输入更新者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新时间" prop="updateTime">
        <el-date-picker clearable
          v-model="queryParams.updateTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:foundations:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:foundations:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:foundations:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:foundations:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="foundationsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="公告类别" align="center" prop="noticeType" />
      <el-table-column label="公告标题" align="center" prop="noticeTitle" />
      <el-table-column label="公告内容" align="center" prop="noticeContent" />
      <el-table-column label="公告状态" align="center" prop="noticeStatus" />
      <el-table-column label="图片路径" align="center" prop="pictureUrl" />
      <el-table-column label="材料路径" align="center" prop="sourcesUrl" />
      <el-table-column label="发布时间" align="center" prop="releaseTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.releaseTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="参与人员" align="center" prop="participants" />
      <el-table-column label="浏览次数" align="center" prop="viewsTimes" />
      <el-table-column label="栏目" align="center" prop="contentColumn" />
      <el-table-column label="是否有心得体会" align="center" prop="haveExperience" />
      <el-table-column label="心得体会内容" align="center" prop="experienceContent" />
      <el-table-column label="文件号" align="center" prop="fileNum" />
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="部门ID" align="center" prop="deptId" />
      <el-table-column label="公告ID" align="center" prop="noticeId" />
      <el-table-column label="课题名称" align="center" prop="issueName" />
      <el-table-column label="课题类别" align="center" prop="topicCategory" />
      <el-table-column label="课题年度" align="center" prop="projectYear" />
      <el-table-column label="承研单位" align="center" prop="researchUnit" />
      <el-table-column label="课题负责人" align="center" prop="projectLeader" />
      <el-table-column label="课题成员" align="center" prop="subjectMembers" />
      <el-table-column label="经费类算" align="center" prop="fundingCategories" />
      <el-table-column label="附件" align="center" prop="annex" />
      <el-table-column label="进展情况" align="center" prop="progress" />
      <el-table-column label="进度周期预警" align="center" prop="progressPeriod" />
      <el-table-column label="课题状态" align="center" prop="issueStatus" />
      <el-table-column label="创建者" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新者" align="center" prop="updateBy" />
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="备注1" align="center" prop="note1" />
      <el-table-column label="备注2" align="center" prop="note2" />
      <el-table-column label="备注3" align="center" prop="note3" />
      <el-table-column label="备注4" align="center" prop="note4" />
      <el-table-column label="备注5" align="center" prop="note5" />
      <el-table-column label="备注6" align="center" prop="note6" />
      <el-table-column label="备注7" align="center" prop="note7" />
      <el-table-column label="备注8" align="center" prop="note8" />
      <el-table-column label="备注9" align="center" prop="note9" />
      <el-table-column label="备注10" align="center" prop="note10" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:foundations:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:foundations:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改技术基础对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="公告标题" prop="noticeTitle">
          <el-input v-model="form.noticeTitle" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="公告内容">
          <editor v-model="form.noticeContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="图片路径" prop="pictureUrl">
          <el-input v-model="form.pictureUrl" placeholder="请输入图片路径" />
        </el-form-item>
        <el-form-item label="材料路径" prop="sourcesUrl">
          <el-input v-model="form.sourcesUrl" placeholder="请输入材料路径" />
        </el-form-item>
        <el-form-item label="发布时间" prop="releaseTime">
          <el-date-picker clearable
            v-model="form.releaseTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择发布时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="参与人员" prop="participants">
          <el-input v-model="form.participants" placeholder="请输入参与人员" />
        </el-form-item>
        <el-form-item label="浏览次数" prop="viewsTimes">
          <el-input v-model="form.viewsTimes" placeholder="请输入浏览次数" />
        </el-form-item>
        <el-form-item label="栏目" prop="contentColumn">
          <el-input v-model="form.contentColumn" placeholder="请输入栏目" />
        </el-form-item>
        <el-form-item label="是否有心得体会" prop="haveExperience">
          <el-input v-model="form.haveExperience" placeholder="请输入是否有心得体会" />
        </el-form-item>
        <el-form-item label="心得体会内容">
          <editor v-model="form.experienceContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="文件号" prop="fileNum">
          <el-input v-model="form.fileNum" placeholder="请输入文件号" />
        </el-form-item>
        <el-form-item label="用户ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID" />
        </el-form-item>
        <el-form-item label="部门ID" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入部门ID" />
        </el-form-item>
        <el-form-item label="公告ID" prop="noticeId">
          <el-input v-model="form.noticeId" placeholder="请输入公告ID" />
        </el-form-item>
        <el-form-item label="课题名称" prop="issueName">
          <el-input v-model="form.issueName" placeholder="请输入课题名称" />
        </el-form-item>
        <el-form-item label="课题类别" prop="topicCategory">
          <el-input v-model="form.topicCategory" placeholder="请输入课题类别" />
        </el-form-item>
        <el-form-item label="课题年度" prop="projectYear">
          <el-input v-model="form.projectYear" placeholder="请输入课题年度" />
        </el-form-item>
        <el-form-item label="承研单位" prop="researchUnit">
          <el-input v-model="form.researchUnit" placeholder="请输入承研单位" />
        </el-form-item>
        <el-form-item label="课题负责人" prop="projectLeader">
          <el-input v-model="form.projectLeader" placeholder="请输入课题负责人" />
        </el-form-item>
        <el-form-item label="课题成员" prop="subjectMembers">
          <el-input v-model="form.subjectMembers" placeholder="请输入课题成员" />
        </el-form-item>
        <el-form-item label="经费类算" prop="fundingCategories">
          <el-input v-model="form.fundingCategories" placeholder="请输入经费类算" />
        </el-form-item>
        <el-form-item label="附件" prop="annex">
          <el-input v-model="form.annex" placeholder="请输入附件" />
        </el-form-item>
        <el-form-item label="进展情况" prop="progress">
          <el-input v-model="form.progress" placeholder="请输入进展情况" />
        </el-form-item>
        <el-form-item label="进度周期预警" prop="progressPeriod">
          <el-input v-model="form.progressPeriod" placeholder="请输入进度周期预警" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注1" prop="note1">
          <el-input v-model="form.note1" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注2" prop="note2">
          <el-input v-model="form.note2" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注3" prop="note3">
          <el-input v-model="form.note3" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注4" prop="note4">
          <el-input v-model="form.note4" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注5" prop="note5">
          <el-input v-model="form.note5" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注6" prop="note6">
          <el-input v-model="form.note6" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注7" prop="note7">
          <el-input v-model="form.note7" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注8" prop="note8">
          <el-input v-model="form.note8" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注9" prop="note9">
          <el-input v-model="form.note9" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注10" prop="note10">
          <el-input v-model="form.note10" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listFoundations, getFoundations, delFoundations, addFoundations, updateFoundations } from "@/api/system/foundations";

export default {
  name: "Foundations",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 技术基础表格数据
      foundationsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        noticeType: null,
        noticeTitle: null,
        noticeContent: null,
        noticeStatus: null,
        pictureUrl: null,
        sourcesUrl: null,
        releaseTime: null,
        participants: null,
        viewsTimes: null,
        contentColumn: null,
        haveExperience: null,
        experienceContent: null,
        fileNum: null,
        userId: null,
        deptId: null,
        noticeId: null,
        issueName: null,
        topicCategory: null,
        projectYear: null,
        researchUnit: null,
        projectLeader: null,
        subjectMembers: null,
        fundingCategories: null,
        annex: null,
        progress: null,
        progressPeriod: null,
        issueStatus: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询技术基础列表 */
    getList() {
      this.loading = true;
      listFoundations(this.queryParams).then(response => {
        this.foundationsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        noticeType: null,
        noticeTitle: null,
        noticeContent: null,
        noticeStatus: "0",
        pictureUrl: null,
        sourcesUrl: null,
        releaseTime: null,
        participants: null,
        viewsTimes: null,
        contentColumn: null,
        haveExperience: null,
        experienceContent: null,
        fileNum: null,
        userId: null,
        deptId: null,
        noticeId: null,
        issueName: null,
        topicCategory: null,
        projectYear: null,
        researchUnit: null,
        projectLeader: null,
        subjectMembers: null,
        fundingCategories: null,
        annex: null,
        progress: null,
        progressPeriod: null,
        issueStatus: "0",
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加技术基础";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getFoundations(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改技术基础";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateFoundations(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFoundations(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除技术基础编号为"' + ids + '"的数据项？').then(function() {
        return delFoundations(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/foundations/export', {
        ...this.queryParams
      }, `foundations_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
